package com.xc.ezplan.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xc.ezplan.admin.entity.AdminAliContent;
import com.xc.ezplan.admin.service.AdminAliContentService;
import com.xc.ezplan.admin.vo.AdminAliContentVo;
import com.xc.ezplan.core.base.BaseSearchBody;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author lixingchen
 * @date 2022/12/04
 * @description 阿里云存储
 */
@RestController
@RequestMapping("/ali/content")
@Api(tags = "阿里云存储")
@RequiredArgsConstructor
public class AdminAliContentController {
    private final AdminAliContentService adminAliContentService;

    @Log("上传阿里云文件")
    @ApiOperation("上传阿里云文件")
    @PostMapping
    @SaCheckPermission("ali.upload")
    public EzResult<Object> uploadContent(@RequestBody MultipartFile file,@RequestParam Long configId) {
        adminAliContentService.uploadContent(file,configId);
        return EzResult.ok();
    }

    @Log("删除阿里云文件")
    @ApiOperation("删除阿里云文件")
    @DeleteMapping
    @SaCheckPermission("ali.delete")
    public EzResult<Object> deleteContent(@RequestBody List<Long> ids,@RequestParam Long configId) {
        adminAliContentService.deleteContent(ids,configId);
        return EzResult.ok();
    }

    @Log("修改阿里云文件")
    @ApiOperation("修改阿里云文件")
    @PutMapping
    public EzResult<Object> updateContent(@RequestBody AdminAliContentVo adminAliContentVo) {
        adminAliContentService.updateContent(adminAliContentVo);
        return EzResult.ok();
    }

    @Log("按条件分页查询用户")
    @ApiOperation("按条件分页查询用户")
    @PostMapping("/page")
    public EzResult<Object> pageQueryContent(@RequestBody BaseSearchBody<AdminAliContent> baseSearchBody) {
        return EzResult.ok(adminAliContentService.pageQueryContent(baseSearchBody));
    }

}
